package com.happiness.base.bean;

import com.happiness.base.enums.SortKeyEnum;
import com.happiness.base.enums.SortTypeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;
import java.util.Objects;

/**
 * 查询条件父级Bean
 * */
@Data
@ApiModel("查询条件父级Bean")
@EqualsAndHashCode(callSuper = false)
public class BaseQueryBean implements Serializable {
    @ApiModelProperty("页数")
    private Integer page;
    @ApiModelProperty("每页记录数")
    private Integer pageSize;
    @ApiModelProperty("排序的键：默认id")
    private String sortKey = SortKeyEnum.CREATE_DATE.key;
    @ApiModelProperty("排序的方式：desc降序、acs升序")
    private String sortType = SortTypeEnum.DESC.key;
    @ApiModelProperty("不用传，用于分页时不采用插件，采用sql语句查询时跨越的查询数")
    private Integer currentSize;
    public void setPage(Integer page) {
        if (!Objects.isNull(page) && page>0){
            this.page = page;
        }else {
            this.page = 1;
        }
    }

    public void setPageSize(Integer pageSize) {
        if (!Objects.isNull(pageSize) && pageSize>0){
            this.pageSize = pageSize;
        }else {
            this.pageSize = 10;
        }
    }
    public BaseQueryBean() {
    }
    public BaseQueryBean(Integer page, Integer pageSize, String sortKey, String sortType) {
        this.setPage(page);
        this.setPageSize(pageSize);
        this.sortKey = sortKey;
        this.sortType = sortType;
    }

    public Integer getCurrentSize() {
        return (this.page-1)*this.pageSize;
    }
}
